package com.myk.game.gobangchess.ai.gravityfour;

public class G4Engine {

    public static int[] G4Engine1(int[][] board, int direction, int dirChanged, int playerTurn, int difficulty) {
        int[] pointSet = {0, 0};
        int killPoint = -1;


        int[] startingSetsresult = StartingSets.startingSets(board, direction, playerTurn, dirChanged);
        int succ = (int) startingSetsresult[0];
        if(succ == 1){
            pointSet = new int[]{(int) startingSetsresult[2], (int) startingSetsresult[1]};
            }
        else{
            int[] killResult = null;
            if(difficulty == 4){
                killResult = KillJudging6plus.killJudgingDeep6(board, direction, playerTurn, dirChanged);
            }else if(difficulty == 3){
                killResult = KillJudging5plus.killJudgingDeep5(board, direction, playerTurn, dirChanged);
            }else if(difficulty == 2){
                killResult = KillJudging3plus.killJudgingDeep3(board, direction, playerTurn, dirChanged);
            }else if(difficulty == 1){
                killResult = KillJudging2plus.killJudgingDeep2(board, direction, playerTurn, dirChanged);
            }
            int isKill = killResult[0];
            killPoint = killResult[1];

            if (isKill == 1) {

                if (killPoint >= 1 && killPoint <= 6) {
                    if (direction == 7) {
                        pointSet = new int[]{killPoint, 1};
                    } else if (direction == 9) {
                        pointSet = new int[]{7 - killPoint, 6};
                    } else if (direction == 8) {
                        pointSet = new int[]{6, killPoint};
                    } else if (direction == 10) {
                        pointSet = new int[]{1, 7 - killPoint};
                    }
                } else {
                    pointSet = new int[]{killPoint, 1};
                }
            } else {
                int[] result = null;
                if(difficulty == 4){
                    result = ScorePredictionDeep3.scorePredictionDeep3(board, direction, playerTurn, dirChanged);
                }else if(difficulty == 3){
                    result = ScorePredictionDeep2ford.scorePredictionDeep2ford(board, direction, playerTurn, dirChanged);
                }else if(difficulty == 2){
                    result = ScorePredictionDeep2ford.scorePredictionDeep2ford(board, direction, playerTurn, dirChanged);
                }else if(difficulty == 1){
                    result = ScorePredictionDeep1ford.scorePredictionDeep1ford(board, direction, playerTurn, dirChanged);
                }
                int maxIndex = result[0];
                
                if (maxIndex >= 1 && maxIndex <= 6) {
                    if (direction == 7) {
                        pointSet = new int[]{maxIndex, 1};
                    } else if (direction == 9) {
                        pointSet = new int[]{7 - maxIndex, 6};
                    } else if (direction == 8) {
                        pointSet = new int[]{6, maxIndex};
                    } else if (direction == 10) {
                        pointSet = new int[]{1, 7 - maxIndex};
                    }
                } else {
                    pointSet = new int[]{maxIndex, 1};
                }
            }
        }
        return new int[]{pointSet[1], pointSet[0]};
    }





    public static int getMaxIndex(int[] array) {
        int maxIndex = 0;
        for (int i = 1; i < array.length; i++) {
            if (array[i] > array[maxIndex]) {
                maxIndex = i;
            }
        }
        return maxIndex + 1;
    }
}
